package com.lincoln.entity.permission;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.lincoln.entity.BaseEntity;
import com.lincoln.entity.user.DbUser;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * 权限(最细)这里需要配合代码实现权限
 */
@Data
@Entity(name = "user_permission")
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})//转json忽略参数
public class DbUserPermission extends BaseEntity {
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @NotFound(action = NotFoundAction.IGNORE)
    protected DbUser user;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "permission_id", nullable = false)
    @NotFound(action = NotFoundAction.IGNORE)
    protected DbPermission permission;

    //白名单还是黑名单
    @Convert(converter = UserPermissionTypeEnum.Convert.class)
    @Column(name = "permission_type", columnDefinition = "int(1)", length = 1, nullable = false)
    UserPermissionTypeEnum permissionType;

}
